package com.qys.livesMall.shop.controller.app;

import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.qys.livesMall.common.result.R;
import com.qys.livesMall.common.utils.MessageUtils;
import com.qys.livesMall.framework.utils.SecurityUtils;
import com.qys.livesMall.shop.dao.H2ShopBaseDao;
import com.qys.livesMall.shop.modal.dto.PurchaseData;
import com.qys.livesMall.shop.modal.dto.SalesData;
import com.qys.livesMall.shop.modal.dto.ShopOrderData;
import com.qys.livesMall.shop.modal.dto.UserData;
import com.qys.livesMall.shop.modal.entity.H2ShopBase;
import com.qys.livesMall.shop.service.ShopStatisticsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @packageName:
 * @className:ShopStatisticsController
 * @Description:
 * @author:guomx
 * @date:2023/7/1215:36
 */
@RequestMapping(value = "/app/statistics")
@RestController
@Tag(name = "店铺统计",description = "店铺统计")
public class ShopStatisticsController {
    @Resource
    private ShopStatisticsService statisticsService;
    @Resource
    private H2ShopBaseDao shopBaseDao;
    @Operation(summary = "销售数据")
    @GetMapping("/sales")
    public R<SalesData> salesDataStatistics(){
        H2ShopBase shopBase = shopBaseDao.getByUserId(SecurityUtils.getUserId());
        if (ObjectUtils.isEmpty(shopBase)){
            return R.fail(MessageUtils.message("system.error.statistics"));
        }
        return statisticsService.salesDataStatistics(shopBase.getId().toString());
    }
    @Operation(summary = "用户数据")
    @GetMapping("/user")
    public R<UserData> userDataStatistics(){
        H2ShopBase shopBase = shopBaseDao.getByUserId(SecurityUtils.getUserId());
        if (ObjectUtils.isEmpty(shopBase)){
            return R.fail(MessageUtils.message("system.error.statistics"));
        }
        return statisticsService.userDataStatistics(shopBase.getId().toString());
    }
    @Operation(summary = "采购数据")
    @GetMapping("/purchase")
    public R<PurchaseData> purchaseDataStatistics(){
        H2ShopBase shopBase = shopBaseDao.getByUserId(SecurityUtils.getUserId());
        if (ObjectUtils.isEmpty(shopBase)){
            return R.fail(MessageUtils.message("system.error.statistics"));
        }
        return statisticsService.purchaseDataStatistics(shopBase.getId().toString());
    }
    @Operation(summary = "用户订单数据数据")
    @GetMapping("/shopOrderData")
    public R<ShopOrderData> shopOrderDataStatistics(){
        H2ShopBase shopBase = shopBaseDao.getByUserId(SecurityUtils.getUserId());
        if (ObjectUtils.isEmpty(shopBase)){
            return R.fail(MessageUtils.message("system.error.statistics"));
        }
        return statisticsService.shopOrderDataStatistics(shopBase.getId().toString());
    }
}




